package com.dkts.oil.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * @author heguanglong
 * @modified by heguanglong
 * @modifiedData 2020/04/01
 */
@SuppressWarnings("hiding")
@Tag(name ="翻页类")
public class PageToList<T> {
    /**
     * 结果集
     */
    @Schema(description = "返回结果集")
    private List<T> rows;

    /**
     * 总数
     */
    @Schema(description = "总数")
    private long total;

    /**
     * 当前页
     */
    @Schema(description = "当前页")
    private long page;

    /**
     * 每页显示数
     */
    @Schema(description = "每页显示数")
    @JsonProperty(value = "pageSize")
    private long pageSize;


    public PageToList() {
    }

    public PageToList(IPage<T> page) {
        this.rows = page.getRecords();
        this.total = page.getTotal();
        this.page = page.getCurrent();
        this.pageSize = page.getSize();
    }

    public PageToList(List list, IPage<T> page) {
        this.rows = page.getRecords();
        this.total = page.getTotal();
        this.page = page.getCurrent();
        this.pageSize = page.getSize();
        this.setRows(list);
    }

    public PageToList(IPage<T> page, List<Map<String, Object>> list) {
        this.rows = new ArrayList<T>();
        for (Map<String, Object> value : list) {
            this.rows.add((T) value);
        }
        this.total = page.getTotal();
        this.page = page.getCurrent();
        this.pageSize = page.getSize();
    }

    public List<T> getRows() {
        return rows;
    }

    public PageToList setRows(List<T> rows) {
        this.rows = rows;
        return this;
    }

    public long getTotal() {
        return total;
    }

    public PageToList setTotal(long total) {
        this.total = total;
        return this;
    }

    public long getPage() {
        return page;
    }

    public PageToList setPage(long page) {
        this.page = page;
        return this;
    }

    public long getPageSize() {
        return pageSize;
    }

    public PageToList setPageSize(long pageSize) {
        this.pageSize = pageSize;
        return this;
    }

}
